package com.proxy.cglibproxy;

import com.proxy.target.BaseTarget;
import org.springframework.cglib.proxy.Enhancer;

/**
 * @Classname CglibProxyTest
 * @Description TODO
 * @Date 2021/8/24 1:04
 * @Created by 张斌
 */
public class CglibProxyTest {
    public static void main(String[] args) {
        BaseTarget baseTarget = new BaseTarget();
        CglibProxyHandler cglibProxyHandler = new CglibProxyHandler(baseTarget);
        BaseTarget proxyInstance = (BaseTarget)cglibProxyHandler.getProxyInstance();
        proxyInstance.targetMethod();
        System.out.println("======================");
        testCglib();
    }
    
    public static void testCglib(){
        BaseTarget baseTarget = new BaseTarget();
        CglibProxyHandler cglibProxyHandler = new CglibProxyHandler(baseTarget);
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(BaseTarget.class);
        enhancer.setCallback(cglibProxyHandler);
        BaseTarget targetProxy = (BaseTarget)enhancer.create();
        targetProxy.targetMethod();
    }
}
